package com.example.backend.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.backend.entity.Collection;
import com.example.backend.entity.CollectionVO;
import com.example.backend.entity.SharedBooklet;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * @author 李月
 * @date 2022/5/4 16:52
 */
@Mapper
public interface CollectionMapper extends BaseMapper<Collection> {
    @Select("SELECT tb_shared_booklet.shared_id,tb_shared_booklet.booklet_id,tb_collection.user_id FROM tb_shared_booklet,tb_collection WHERE tb_shared_booklet.shared_id=tb_collection.shared_id AND tb_shared_booklet.booklet_id=#{bookletId} AND tb_collection.user_id=#{userId}")
    CollectionVO getCollection(@Param("bookletId") int bookletId, @Param("userId") int userId);

    @Delete("DELETE FROM tb_collection WHERE user_id=#{userId} AND shared_id=(SELECT tb_shared_booklet.shared_id FROM tb_shared_booklet WHERE tb_shared_booklet.booklet_id=#{bookletId})")
    void deleteCollection(@Param("bookletId") int bookletId, @Param("userId") int userId);
}
